
n=int(input())
nums=list(map(int,input().split()))
result=nums[0]

d={}
for num in nums:
    if d.get(num) is None:
        d[num]=1
    else:
        d[num]+=1
    if d[num]>d[result] or d[num]==d[result] and num<result:
        result=num

print(result)